package basedto

import jsoniter "github.com/json-iterator/go"

type JsonResult struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data string `json:"data"`
	BaseEntity
}

func NewJsonResult() *JsonResult {
	result := &JsonResult{}
	result.InitProxy(result)
	return result
}

func (result *JsonResult) String() string {
	s, _ := jsoniter.Marshal(result)
	return string(s)

}

func (result *JsonResult) ToString() string {
	s, _ := jsoniter.MarshalIndent(result, "", " ")
	return string(s)

}

func (result *JsonResult) Success() *JsonResult {
	result.Code = CODE_SUCCESS
	result.Msg = "成功"
	return result
}

func (result *JsonResult) SuccessData(data string) *JsonResult {
	result.Code = CODE_SUCCESS
	result.Msg = "成功"
	result.Data = data
	return result
}
func (result *JsonResult) SuccessMessage(msg string, data string) *JsonResult {
	result.Code = CODE_SUCCESS
	result.Msg = msg

	result.Data = data
	return result
}

func (result *JsonResult) Fail() *JsonResult {
	result.Code = CODE_FAIL
	result.Msg = "失败"
	return result
}

func (result *JsonResult) FailMessage(msg string) *JsonResult {
	result.Code = CODE_FAIL
	result.Msg = msg
	return result
}

func (p *JsonResult) SetData(s string) {
	p.Data = s
}

func (p *JsonResult) GetData() string {

	return p.Data
}
